<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>写博客</title>
<style type="text/css">
    a {
    	color: black;
    	text-decoration: none;
    }
    a:hover {
        color: red;
    }
    .tijiao {
        position: relative;
    	left: 45px;
    }
    ul li {
	    list-style:none;
    }
    .bkxz{
        position: relative;
    	left: 800px;
    }
</style>
</head>
<body>
<h2 class="tijiao">发表博客</h2>
<span>
<!--  
<select class="bkxz">
    <option value="0" onclick="lxwu()">类型选择</option>
    <option value="1" onclick="lxcs()">测试博客</option>
    <option value="2" onclick="lxpt()">普通博客</option>
    <option value="3" onclick="lxpt()">plm博客</option>
</select>
-->
<%!
    private static final String JDBC_URL = "jdbc:mysql://localhost:3309/blog?useUnicode=true&characterEncoding=utf8";
	private static final String DB_USER = "root";
	private static final String DB_PWD = "ZLWL";
	Map<String, String> hashMaps = new HashMap<String, String>();
%> 
<%
 	try {
 		Class.forName("com.mysql.jdbc.Driver").newInstance();
 	} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
 		e.printStackTrace();
 	}
 	Connection conn;
 	try {
 		conn = DriverManager.getConnection(JDBC_URL, DB_USER, DB_PWD);
 		Statement stmt = conn.createStatement();
 		String sqlz = "select count(id) total from blog_type";
 		ResultSet rsz = stmt.executeQuery(sqlz);
 		System.out.println("blog_typelist_number1:" + rsz);
 		int setnum = 0;
 		while (rsz.next()) {
 			int getnum = rsz.getInt(1);
 			System.out.println("blog_typelist_number1:" + getnum);
 			setnum = getnum;
 		}
 		System.out.println("blog_typelist_number1:" + setnum);
 		System.out.println("****************************************");
 		String sqly = "select id from blog_type";
 		ResultSet rsy = stmt.executeQuery(sqly);
 		System.out.println("blog_typelist_number2:" + rsy);
 		Map<String, String> hashMap1 = new HashMap<String, String>();
 		int i = 1;
 		while (rsy.next()) {
 			hashMap1.put("id" + i, rsy.getString("id"));
 			hashMaps.put("id" + i, rsy.getString("id"));
 			System.out.println(hashMap1.get("id" + i));
 			i++;
 		}
 		System.out.println("****************************************");
 		String sqlx = "select type_name from blog_type";
 		ResultSet rsx = stmt.executeQuery(sqlx);
 		System.out.println("blog_typelist_number3:" + rsx);
 		Map<String, String> hashMap2 = new HashMap<String, String>();
 		int j = 1;
 		while (rsx.next()) {
 			hashMap2.put("type_name" + j, rsx.getString("type_name"));
 			System.out.println(hashMap2.get("type_name" + j));
 			j++;
 		}
 		System.out.println("****************************************");
 	    response.getWriter().append("<select class='bkxz' id='slt' onchange='selectInput(this)'>");
 	    response.getWriter().append("<option value='0' onclick='lxwu()'>类型选择</option>");
 		int k = 1;
 		while (k < (setnum + 1)) {
 			System.out.println(hashMap1.get("id" + k));
 			System.out.println(hashMap2.get("type_name" + k));
 			System.out.println("Maps_id:" + hashMaps.get("id" + k));
 			response.getWriter().append("<option value='" 
 			+ hashMap1.get("id" + k) + "' onclick='lxcs()''>" 
 			+ hashMap2.get("type_name" + k) + "</option>");
 			k++;
 		}
 	    response.getWriter().append("</select>");
 		rsx.close();
 		rsy.close();
 		rsz.close();
 		stmt.close();
 		conn.close();
 	} catch (SQLException e) {
 		e.printStackTrace();
 	}
 %> 
	</span>
	<form id="blog-form" method="post" name="passForm">
		<ul>
			<li>标&nbsp;&nbsp;&nbsp;&nbsp;题：<input type="text" name="title" /></li>
			<li>内&nbsp;&nbsp;&nbsp;&nbsp;容：<textarea id="editor" name="content" rows="10" cols="50"></textarea></li>
			<li><input type='hidden' name="test2"></li>
		</ul>
		<div class="tijiao"><a id="save" href="javascript:;">提交</a></div>
	</form>
	<!--  
	<form method="post" name="pasorm" action="zhongjie.jsp">
		<input type='hidden' name="test3">
	</form>
	-->
	<script type="text/javascript" src="/static/js/jquery.min.js"></script>
	<script type="text/javascript" src="/static/js/ueditor/ueditor.config.js"></script>
	<script type="text/javascript" src="/static/js/ueditor/ueditor.all.min.js"></script>
	<script type="text/javascript">
	$(function(){
		$('#save').on('click',function(){
			$.post('/addblog',$('#blog-form').serialize(),function(data){
				alert(data);
				console.log(data);
			});
		});
		
		var ue = UE.getEditor('editor');
	});
	var tyds = 0;
	function selectInput(choose) {    
	    tyds = document.getElementById("slt").value;   
	}
	function lxwu(){
		tyds = 0;
		setinput(tyds);
	}
	function lxcs(){
		//alert(tyds);
		setinput(tyds);
	}
	function setinput(test2){
		document.passForm.test2.value = test2;
	    //document.write("test2:" + test2);
	    //document.write("<br>");
	    //document.passForm.submit();
	}
    //setinput(tyds);
    /*
    function setinputww(test3){
		document.pasorm.test3.value = test3;
	    document.write("<br>");
	    document.write("test3:" + test3);
	    document.pasorm.submit();
	}
    setinputww("23333333");
    */
    <%--
	<%
	String xczcz = (String)request.getSession().getAttribute("tisdz");  
    System.out.println(xczcz);
	%>
	<%=xczcz%>
	--%>
	</script>
</body>
</html>